<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>浩鲸知识库</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="<%=basePath%>modules/micro/imgs/logo.ico">
    <link href="<%=basePath%>frm/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=basePath%>modules/micro/html/scrollcss.css" rel="stylesheet">

    <script type="text/javascript" charset="utf-8" src="<%=basePath%>frm/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=basePath%>frm/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="<%=basePath%>frm/ueditor/lang/zh-cn/zh-cn.js"></script>
  </head>
  <body onload="getKnowlibCode();">
    <div style="height:150px;position:relative;width:100%">
      <div id="titleDiv" class="panel-heading" style="background-image: url(<%=basePath%>modules/micro/imgs/bgimg.jpg);color: #ffffff;margin:auto;width:100%">
        <h3 class="panel-title">
          <a href="<%=basePath%>modules/micro/html/micro.jsp"><h1>浩鲸知识库</h1></a>
        </h3>
      </div>
      <div id="myPageDiv">
        <form id="subjectForm" action="<%=basePath%>subject/insertAnonymouSubject.do" method="post">
        <ul class="nav nav-tabs nav-pills">
          <li ><a class="glyphicon glyphicon-ok" href="#" onclick="saveSubject('Y')">保存</a></li>
          <li ><a class="glyphicon glyphicon-ok" href="#" onclick="saveSubject('N')" title="文档不挂在到左侧目录列表，请通过URL访问或是挂在到其他文档中.">保存(无目录)</a></li>
          <li ><a class="glyphicon glyphicon-home" href="<%=basePath%>">首页</a></li>
          <li ><a class="glyphicon glyphicon-arrow-up" href="#" onclick="window.history.back(-1)">返回上一页</a></li>
        </ul>
        <div id="toolbarDiv" style="position: relative;width: 100%;"></div>
        <div class="row" style="color:blue;font-family: bold;margin-top:2px;overflow:auto;font-size: 25px;text-align: center;width: 100%">
          <div style="height: 55px;border:1px solid #f5f5f5;">
            <label>主题：</label>
            <input type="text" id="subjectTitle" name="subjectTitle" style="margin-top: 7px;margin-bottom: 2px;width:70%;color: #080808"/>
            <input type="hidden" id="subjectCatName" name="subjectCatName"/>
            <input type="hidden" id="pSubjectId" name="pSubjectId"/>
            <input type="hidden" id="userName" name="userName"/>
            <input type="hidden" id="modifyUserName" name="modifyUserName"/>
          </div>
        </div>
        <div style="margin:auto;width:100%;height:100%;margin-top:2px;">
          <div id="subjectDetailDiv" style="font-family: bold;position:relative; height:100%; overflow:auto;text-align: left;">
            <div>
              <div id="subjectContent" name="subjectContent" type="text/plain"  style="width:100%;position:relative; height:360px; overflow:hidden;"></div>
            </div>
          </div>
        </div>
        <!--
        <div style="margin:auto;width:100%">
          <div id="subjectDetailDiv" class="col-md-12" style="font-family: bold;overflow:auto;font-size: 16px;text-align: left;text-align: center">
            <div>
              <script id="subjectContent" name="subjectContent" type="text/plain" style="width:100%;height:360px"></script>
            </div>
          </div>
        </div>
        -->
        </form>
      </div>
    </div>
    <script src="<%=basePath%>frm/bootstrap-3.3.7/js/jquery.min.js"></script>
    <script src="<%=basePath%>frm/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="<%=basePath%>frm/layer/layer.js"></script>
    <script type="application/javascript">
      var ue = UE.getEditor('subjectContent',{
        autoHeightEnabled: true,
        autoFloatEnabled: true
      });
      $("#toolbarDiv").html($("#edui1_toolbarbox")[0]);
      var curScreemHeight = $(document).height() - 250;
      $("#subjectDetailDiv").height(curScreemHeight);
      /**
       * 保存匿名发布的主题
       */
      function saveSubject(flag) {
        if (isLogin() ) {
            var subjectTitle = $("#subjectTitle").val();
            if(subjectTitle) {
                if ("Y" === flag) {
                    $("#pSubjectId").val("-1");
                }
                else {
                    $("#pSubjectId").val("no_catalog");
                }

                $("#userName").val(window.userName);
                $("#modifyUserName").val(window.userName);
                $("#subjectCatName").val(window.knowlibcode);

                $("#subjectForm").submit();
            } else {
                layer.msg('主题项必填!', {icon: 5});
            }
        }
      };

      /**
      * 保存匿名发布的主题
       */
      function saveSubjectForm() {
      }

      /**
       * 从cookie中获取用户信息
       * */
      function isLogin() {
          // 如果未登陆给出提示
          var hasCook = false;
          var cookieVue = document.cookie;
          var cookieArr = decodeURI(cookieVue).split(";");
          if (cookieArr) {
              for (var i=0;i<cookieArr.length;i++) {
                  if (cookieArr[i].indexOf("username") != -1) {
                      var uname = cookieArr[i].split("=");
                      hasCook = true;
                      window.userName = uname[1];
                  }
                  if (cookieArr[i].indexOf("knowlibcode") != -1) {
                      var knowlibcode = cookieArr[i].split("=");
                      window.knowlibcode = knowlibcode[1] || "changsha";
                  }
              }
              if (!hasCook) {
                  layer.confirm('未登陆，不可编辑，是否跳转登陆页面?', {icon: 3, title:'提示'}, function(){
                      var sourceUrl = window.location.href;
                      window.location.href="<%=basePath%>modules/micro/login/login.jsp?sourceUrl=" + sourceUrl;
                  });
              }
          }
          return hasCook;
      }

      /**
       * 从缓存中获取知识库
       * */
      function getKnowlibCode() {
          var hasknowlibcode = false;
          var cookieVue = document.cookie;
          var cookieArr = decodeURI(cookieVue).split(";");
          if (cookieArr) {
              for (var i=0;i<cookieArr.length;i++) {
                  if (cookieArr[i].indexOf("username") != -1) {
                      var uname = cookieArr[i].split("=");
                      window.userName = uname[1];
                  }
                  if (cookieArr[i].indexOf("knowlibcode") != -1) {
                      hasknowlibcode = true;
                      var knowlibcode = cookieArr[i].split("=");
                      window.knowlibcode = knowlibcode[1] || "changsha";
                  }
              }
              if (!hasknowlibcode) {
                  window.knowlibcode = "changsha";
              }
          }
          $("#toolbarDiv").html($("#edui1_toolbarbox")[0]);
      }
    </script>
  </body>
